﻿using System;
using System.Threading;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ApiToolkit
{
    public struct GUID
    {
        public const string GUID_BlockBehavior = "fefb9590-4972-4893-b02a-76063611b745";
        public override string ToString()
        {
        	
            var p1 = part1.ToString("x");
            var p2 = part2.ToString("x");
            while(p1.Length < 32)
            {
            	p1 = "0" + p1;
            }
            while(p2.Length < 32)
            {
            	p2 = "0" +p2;
            }
            var guid = p1 + p2;
            guid = guid.Insert(8, "-");
            guid = guid.Insert(13, "-");
            guid = guid.Insert(18, "-");
            guid = guid.Insert(23, "-");
            return guid;
        }
        ulong part1, part2;
        public static GUID CreateRandom()
        {

            GUID guid = new GUID(RandomUlong(), RandomUlong());
            return guid;
        }
        private static ulong RandomUlong()
        {
            Thread.Sleep(7);
            System.Random rand = new System.Random();
            uint part1,part2;
            part1 = (uint)rand.Next(int.MinValue, int.MaxValue);
            Thread.Sleep(50);
            part2 = (uint)rand.Next(int.MinValue, int.MaxValue);
            return (((ulong)part1) << 32) + ((ulong)part2);
        }
        public GUID(ulong part1, ulong part2)
        {
            this.part1 = part1;
            this.part2 = part2;
        }
    }
}
